<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'show.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<style type="text/css">
		#main{
			width: 700px;
			height: 500px;
			margin: 0 auto;
		}
	</style>
  </head>
  
  <body>
   <div id="main">
   		<table border="1px">
   			<tr>
   				<td colspan="7"><h1>下面是所有商品</h1></td>
   			</tr>
   			<tr>
   				<td colspan="7">
   					<form action="productAction!show?page.nowpage=1" method="get">
   						关键字搜索：<input type="text" name="likename" 
   						value="<s:if test="num==1"><s:property value="likename"/></s:if>">
   						<input type="submit" value="搜索">
   					</form>
   				</td>
   			</tr>
   			<tr>
   				<td colspan="7">
   					排序方式：
   					<select onchange="javascript:location.href='productAction!show?page.nowpage=1&likename=${likename}&choose='+this.options[this.selectedIndex].value;">
   						<option value="0" ${choose==0?"selected":""}>默认</option>
   						<option value="1" ${choose==1?"selected":""}>价格顺序</option>
   						<option value="2" ${choose==2?"selected":""}>价格倒序</option>
   						<option value="3" ${choose==3?"selected":""}>时间顺序</option>
   						<option value="4" ${choose==4?"selected":""}>时间倒序</option>
   					</select>
   				</td>
   			</tr>
   			<tr>
   				<td>商品编号</td>
   				<td>商品名称</td>
   				<td>商品介绍</td>
   				<td>商品库存</td>
   				<td>商品价格</td>
   				<td>添加时间</td>
   				<td>操作</td>
   			</tr>
 			<s:iterator value="page.getlist">
 				<tr>
 					<td>${id }</td>
 					<td align="center">
 						<img src="img/${img}.jpg" width="100px"><br/>
 						${name}
 					</td>
 					<td>${note }</td>
 					<td>${stock }</td>
 					<td>${price }</td>
 					<td>
						<s:date name="addDate" format="yyyy年MM月dd日 HH时mm分ss秒 E"/>
					</td>
					<td>
						<form action="onpAction!addONP" method="get">
							<input type="hidden" name="onp.product.id" value="${id }">
							<input type="hidden" name="onp.price" value="${price }">
							购买数量：<input type="text" name="onp.num">
							<input type="submit" value="购买商品">
						</form>
					</td>
 				</tr>
 			</s:iterator>
 			<tr>
 				<td colspan="7">
 					第${page.nowpage}页/共${page.allpage}
 					<s:if test="page.nowpage>1">
 						<a href="productAction!show?page.nowpage=${page.nowpage-1}&likename=${likename}&choose=${choose}">上一页</a>
 					</s:if>
 					<s:if test="page.nowpage==1">
 						上一页
 					</s:if>
 					<s:iterator var="p" begin="1" end="page.allpage">
 						<a href="productAction!show?page.nowpage=<s:property value="#p"/>&likename=${likename}&choose=${choose}">
 							<s:property value="#p"/>
 						</a>
 					</s:iterator>
 					<s:if test="page.nowpage<page.allpage">
 						<a href="productAction!show?page.nowpage=${page.nowpage+1}&likename=${likename}&choose=${choose}">下一页</a>
 					</s:if>
 					<s:if test="page.nowpage==page.allpage">
 						下一页
 					</s:if>
 				</td>
 			</tr>
   		</table>
   </div>
  </body>
</html>
